<template>
	<el-container>
		<el-main class="nopadding">
			<el-container>
				<el-header>
					<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
				</el-header>
				<el-main class="nopadding">
					<scTable ref="table" :data="tableData" stripe v-loading="loading" :default-sort = "{ prop: 'createTime',order: 'descending'}">
						<el-table-column type="index" label="#" width="50"></el-table-column>
						<el-table-column label="发件人" prop="from" width="200" :show-overflow-tooltip="true"></el-table-column>
						<el-table-column label="邮件标题" prop="subject" width="300" :show-overflow-tooltip="true"></el-table-column>
						<el-table-column label="邮件内容" prop="content" width="500" :show-overflow-tooltip="true"></el-table-column>
						<el-table-column label="收件时间" prop="createTime" width="150"></el-table-column>
						<el-table-column label="附件" prop="attachFileName" width="300" :show-overflow-tooltip="true"></el-table-column>
						<el-table-column label="操作" fixed="right" align="right" width="120">
							<template #default="scope">
								<el-button-group>
									<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
									<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
										<template #reference>
											<el-button text type="primary" size="small">删除</el-button>
										</template>
									</el-popconfirm>
								</el-button-group>
							</template>
						</el-table-column>
					</scTable>
				</el-main>
			</el-container>
		</el-main>
	</el-container>
	<webMailDetails v-if="dialog.save" ref="webMailDetailsDialog" @closed="dialog.save=false"></webMailDetails>
</template>
<script>

import AttachMenu from "@/views/module/attachMenu.vue";
import scSelectFilter from "@/components/scSelectFilter/index.vue";
import webMailDetails from "./webmaildetails";
export default {
	emits: ['success', 'closed'],
	components: {scSelectFilter, AttachMenu,webMailDetails},
	data() {
		return {
			loading:false,
			tableData:[],
			dialog: {
				save: false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "半月内",
							value: "4"
						},
						{
							label: "一月内",
							value: "5"
						}
					]
				},
			],
			search:{
				date:''
			},
		}
	},
	mounted() {
		this.getMyWebEmail();
	},
	methods: {
		table_show(row,index){
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.webMailDetailsDialog.open().setData(row,this.search.date);
			})
		},
		filterChange(data){
			this.search.date = data.date;
			this.getMyWebEmail();
		},
		//显示
		async getMyWebEmail() {
			this.loading = true;
			var res = await this.$API.email.webEmail.getMyWebEmail.get(this.search);
			if (res.code == 200) {
				this.tableData = res.data;
				this.loading = false;
			} else {
				this.$alert(res.message, "提示", {type: 'error'});
				this.loading = false;
			}
		},
		async table_del(row,index) {
			var res = await this.$API.email.webEmail.deleteWebMail.post({date:this.search.date,title:row.subject,revDate:row.createTime});
			if (res.code == 200) {
				this.getMyWebEmail();
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
	}
}
</script>
